

{mfdeclre.i}


SESSION:SET-WAIT-STATE("") .

DEFINE VARIABLE hDoc AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE hTable AS HANDLE.
DEFINE VARIABLE hField AS HANDLE.
DEFINE VARIABLE hLine AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.

DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE j AS INTEGER.
DEFINE VARIABLE k AS INTEGER.

CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hTable.
CREATE X-NODEREF hField.
CREATE X-NODEREF hLine.
CREATE X-NODEREF hText.

DEFINE VARIABLE str AS CHARACTER .
DEFINE VARIABLE ret AS CHARACTER .

FORM
    ad_addr  
    ad_name  FORMAT "x(30)"
    ad_attn  FORMAT "x(12)"
    ad_line1 FORMAT "x(60)" 
    WITH FRAME cust WIDTH 120 STREAM-IO DOWN .

/*read in the file created in the last example*/
hDoc:LOAD("file", "f:\hk_src\xml\cust.xml", FALSE).

hDoc:GET-DOCUMENT-ELEMENT(hRoot).

REPEAT i = 1 TO hDoc:NUM-CHILDREN WITH FRAME cust :

    hDoc:GET-CHILD(hTable,i).

    IF hTable:NUM-CHILDREN < 1 THEN NEXT.

    REPEAT j = 1 TO hTable:NUM-CHILDREN:

        hTable:GET-CHILD(hField,j).

        IF hField:NUM-CHILDREN < 1 THEN NEXT.

        str = hField:GET-ATTRIBUTE("CustNo").
/*
        {gprunp.i "hkbase64" "p" "base64Decode" "(input str, output ret)"}
*/
        DISP 
           str @ ad_addr WITH FRAME cust STREAM-IO .

        str = hField:GET-ATTRIBUTE("CustName").
        {gprunp.i "hkbase64" "p" "base64Decode" "(input str, output ret)"}
            DISP 
                ret @ ad_name WITH FRAME cust STREAM-IO .

        REPEAT k = 1 TO hField:NUM-CHILDREN:

            hField:GET-CHILD(hLine,k).

            IF hLine:NUM-CHILDREN < 1 THEN NEXT.

            hLine:GET-CHILD(hText,1).
        
            str = hTEXT:NODE-VALUE .
            {gprunp.i "hkbase64" "p" "base64Decode" "(input str, output ret)"}
            IF hLine:NAME = "Address" THEN DO:
                DISP
                    ret @ ad_line1
                    WITH FRAME cust STREAM-IO .
            END.
            ELSE IF hLine:NAME = "ContactMan" THEN DO:
                DISP
                    ret @ ad_attn
                    WITH FRAME cust STREAM-IO .
            END.
        END.
        DOWN 1 WITH FRAME cust STREAM-IO .
    END.
END.

PAUSE NO-MESSAGE.
